<?php

require_once("../../init.php");

use cogpowered\FineDiff\Diff;
use cogpowered\FineDiff\Granularity\Paragraph;

$old_file = $_GET["old_file"];
if (file_exists($old_file)) {
    $old_content = file_get_contents($old_file);
} else {
    die("原文件不存在!");
}
$new_file = $_GET["new_file"];
if (file_exists($new_file)) {
    $new_content = file_get_contents($new_file);
} else {
    die("新文件不存在!");
}

$granularity = new Paragraph();  // 使用段落粒度
$contents = (new Diff($granularity))->render($old_content, $new_content);

if (empty($contents)) {
    $contents = htmlspecialchars(file_get_contents($new_file));
}
$show = <<<COF
    <style type="text/css">
        del {
            background: none repeat scroll 0 0 pink;
        }
        ins {
            background: none repeat scroll 0 0 lightgreen;
            text-decoration: none;
        }
    </style>
    <div class="content">
        <pre class="diff">$contents</pre>
    </div>
COF;
echo $show;
